<?php

namespace app\model;

use think\Model;

class AutoTask extends Model
{
    /**
     * 自动任务库
     */
    protected $createTime = 'create_date';

    public function getValueAttr($name)
    {
        return (int)$name;
    }

    public function addDataModel($param)
    {
        return self::create($param);
    }

    public function getFindDataModel($param)
    {
        $data = $this->where (['clue_type'=>$param['clue_type'],'task_type'=>$param['task_type']])->findOrEmpty ();
        if (!$data->isEmpty ()){
            return $data->toArray ();
        }
        return null;
    }

    public function editFindModel($param)
    {
        return $this->where (['clue_type'=>$param['clue_type'],'task_type'=>$param['task_type']])->save ($param);
    }

    /**
     * 查询自动条件
     * @param $clue_type
     * @param $task_type
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getExeData($clue_type,$task_type):array
    {
        return $this->where (['clue_type'=>$clue_type,'task_type'=>$task_type])->select()->toArray ();
    }

    /**
     * 删除条件
     */
    public function delWhereModel($clue_type,$task_type)
    {
        $this->where (['clue_type'=>$clue_type,'task_type'=>$task_type])->delete();
        return $this->where(['field'=>''])->delete ();
    }

}